
# def foreach(function, iterator):#定义一个函数，一个参数是要执行的函数，iterator循环次数
#     for item in iterator:
#         #print(item)
#         print(iterator)
#         function(item)#item是数字
# foreach( lambda value:print(value), range(5))#调用函数,lambda返回print(value),value是声明value

# def echo_all_even(value):
#     if value % 2 == 0:
#         print(value)
# foreach(echo_all_even, range(5))

# print('''pyt
#
# hon''')
# print('pyt'
#       ''
#       'hon')
# print('间\t\t\t\t\t\t\t\t\t\t距')

# user_1 = '韩韩'
# user_2 = '李磊'
# print('{}{}:hello'.format(user_2, user_1))
# print(f'{user_1}对{user_2}说:hello')#引用变量{}
# my_list = [1, 2, 'a', 1.3]
# #my_list.append('python')
# #my_list.insert(1, '')
# #my_list.extend((22, 33, 44))#
# #my_list.pop(2)删除元素
# print(my_list)

#元组是不可变的列表
# my_yuan = (0, 1, 2, 3, 4)
# print(my_yuan[1:3])#元组可以[],负数时反向索引,1:3一到三

# user = {
#     'name': 'zhu',#字符串形式
#     'age': 18,
#     'gender': 'male'
# }
# user['fav'] = '打游戏'#给对象key:value值
# print(user['name'])#检索[],字符串形式
# def sum(a, b):
#     s = 0
#     while a <= b:
#         s += a
#         a += 1
#     return s#函数要有return
# print(sum(1, 100))

# f = open('zhu.txt', encoding='utf-8')#解码参数
# print(s)
# f.close()

# f = open('write.txt', mode='w', encoding='utf-8')
# f.write('猪来了')
# f.close()

# class person:
#     def __init__(self, name, gender, birthday):
#         self.name = name
#         self.gender = gender
#         self.birthday = birthday
#     def say(self, word):
#         print(f'{self.name}说:{word}')
#
# zhang_san = person('张三', '男', '50000505')
# zhang_san.say('nmsl')
# print(zhang_san.birthday)

from PIL import Image, ImageDraw, ImageFont
import cv2

bg = Image.new('RGB', (2480, 3580), (255, 255, 255))
draw = ImageDraw.Draw(bg)
#print(bg.size)
#cv2无用尝试代码
img = cv2.imread(r"draw")
#print(img)#null
xmin = 1000
xmax = 2000
ymin = 1000
ymax = 3000
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 5)

path_to_ttf = r'c:\windows\fonts\msyh.ttc'#字体路径
typeface = ImageFont.truetype(path_to_ttf, 100)# 创建字体
tempwords = '编程从入门到入土\n编程从入门到放弃'
#print(len(tempwords))#17
twice = tempwords.split('\n')
#print(len(twice))
words = tempwords.split('\n')[0]
#print(len(words))
#print(len(words[1]))
# if isinstance(words, str):#是字符串
#     print("is str")
# else:
#     print(" is not str")


xlt, ylt, xrt, yrt, xlb, ylb, xrb, yrb = 80, 80, 2000, 80, 80, 3000, 2000, 3000
xtdash, ytdash, xbdash, ybdash = 180, 80, 180, 280
xldash, yldash, xrdash, yrdash = 80, 180, 280, 180
xtq, ytq, xbq, ybq = 280, 80, 280, 280
xlq, ylq = 80, 280
for i in range(0, len(twice)):
    if i > 0:
        xtdash, xbdash = 180, 180
        xldash, xrdash = 80, 280
        xtq, xbq = 280, 280
        xlq = 80

        #y坐标换行
        ytdash += 200
        ybdash += 200
        yldash += 200
        yrdash += 200
        ytq += 200
        ybq += 200
        ylq += 200
    for a in range(0, len(words)):
        #画框
        draw.line((xlt, ylt) + (xrt, yrt), fill=(0, 155, 0), width=5)#两个元组相加() + (),起点到终点
        draw.line((xlt, ylt) + (xlb, ylb), fill=(0, 155, 0), width=5)
        draw.line((xlb, ylb) + (xrb, yrb), fill=(0, 155, 0), width=5)
        draw.line((xrt, yrt) + (xrb, yrb), fill=(0, 155, 0), width=5)
        #虚线十
        draw.line((xtdash, ytdash) + (xbdash, ybdash), fill=(0, 155, 0), width=1)
        draw.line((xldash, yldash) + (xrdash, yrdash), fill=(0, 155, 0), width=1)
        #小框small square
        draw.line((xtq, ytq) + (xbq, ybq), fill=(0, 155, 0), width=1)
        draw.line((xlq, ylq) + (xbq, ybq), fill=(0, 155, 0), width=1)
        xtdash += 200
        xbdash += 200

        xldash += 200
        xrdash += 200

        xtq += 200
        xbq += 200

        xlq += 200


x3, y3 = 120, 115
for i in range(0, len(twice)):
    #print(i)#还是没执行
    x3 = 120#调整第二行x的初始位置
    if i > 0:
        words = twice[i]
    for a in range(0, len(words)):
        #print(len(words[a]))#压根就没执行
        #print(a)
        draw.text((x3, y3), words[a], font=typeface, fill=(0, 0, 0))# draw对象上写字
        #print(x3)
        x3 += 200
    y3 += 200

# print(bg.mode)
# bg.save("bg.png")#save会把图片保存在同一个目录下
bg.show()


# import cv2
# from PIL import Image, ImageDraw
#
# if __name__ == '__main__':
#     bg = Image.new('RGB', (2480, 3580), (255, 255, 255))
#     draw = ImageDraw.Draw(bg)
#     imgPath = r"draw"
#     img = cv2.imread(imgPath)
#     print(img)
#     xmin = 100
#     xmax = 200
#     ymin = 100
#     ymax = 300
#     cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 5)
#     cv2.imshow('draw', img)#地址为什么要重复给
#     cv2.waitKey()#wait等待，不要管关
